package etnorservice.etnor_service.service.impl;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/11/30/11:29
 **/



import etnorservice.etnor_service.domain.po.Reply;
import etnorservice.etnor_service.mapper.ReplyMapper;
import etnorservice.etnor_service.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Date;

@Service
public class ReplyServiceImpl implements ReplyService {

    @Autowired
    private ReplyMapper replyMapper;

    @Override
    @Transactional
    public Reply createReply(Reply reply) {
        reply.setCreateTime(new Date());
        reply.setUpdateTime(new Date());
        reply.setLikeCount(0);
        replyMapper.insert(reply);
        return reply;
    }

    @Override
    public List<Reply> getRepliesByCommentId(Long commentId) {
        return replyMapper.findByCommentId(commentId);
    }

    @Override
    @Transactional
    public Reply updateReply(Reply reply) {
        reply.setUpdateTime(new Date());
        replyMapper.update(reply);
        return reply;
    }

    @Override
    @Transactional
    public void deleteReply(Long id) {
        replyMapper.deleteById(id);
    }

    @Override
    public Reply getReplyById(Long id) {
        return replyMapper.findById(id);
    }

    @Override
    @Transactional
    public void updateReplyLikes(Long id, int likesCount) {
        replyMapper.updateLikesCount(id, likesCount);
    }
}